package training;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_5_21_Training {
    //工作安排
    public static void main33(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while(T>0){
            T--;
            int n = scanner.nextInt();
            //dpFun(n);
            int[][] nums = new int[n+1][3];
            int max = Integer.MIN_VALUE;
            for (int i = 1; i <= n; i++) {
                nums[i][0] = scanner.nextInt();
                nums[i][1] = scanner.nextInt();
                nums[i][2] = scanner.nextInt();
                max = Math.max(max,nums[i][1]);
            }
            Arrays.sort(nums, Comparator.comparingInt(a -> a[1]));
            int[] dp = new int[max+1];
//            for (int i = 1; i <= max; i++) {
//                dp[0][i] = 0x3f3f3f3f;
//            }
            int ret = Integer.MIN_VALUE;
            for (int i = 1; i <= n; i++) {
                for (int j = nums[i][1]; j >= nums[i][0]; j--) {
                    //dp[j] = dp[j];
                    //if(j>=nums[i][0]){
                        dp[j] = Math.max(dp[j],dp[j-nums[i][0]]+nums[i][2]);
                        //break;
                    //}
                    ret = Math.max(ret,dp[j]);
                }
            }
            System.out.println(ret);
        }
    }

    public static void dpFun(int n){
        Scanner scanner = new Scanner(System.in);
        int[][] nums = new int[n+1][3];
        int max = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            nums[i][0] = scanner.nextInt();
            nums[i][1] = scanner.nextInt();
            nums[i][2] = scanner.nextInt();
            max = Math.max(max,nums[i][1]);
        }
        int[][] dp = new int[n+1][max+1];
        int ret = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= nums[i][1]; j++) {
                dp[i][j] = dp[i-1][j];
                if( j>=nums[i][0]){
                    dp[i][j] = Math.max(dp[i][j],dp[i][j-nums[i][0]]+nums[i][2]);
                }
                ret = Math.max(ret,dp[i][j]);
            }
        }
        System.out.println(ret);
    }

    //暖炉与水豚
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] nums = new int[r+1][c+1];
        int[][] nums2 = new int[r+1][c+1];
        char[][] map = new char[r+1][c+1];
        for (int i = 1; i <= r; i++) {
            String string = scanner.next();
            for (int j = 1; j <= c; j++) {
                char ch = string.charAt(j-1);
                map[i][j] = ch;
//                if(ch=='m'){
//                    warm(i,j,r,c,nums);
//                }else if(ch=='c'){
//                    cold(i,j,r,c,nums);
//                }
            }
        }

        for (int i = 1; i <= r; i++) {
            for (int j = 1; j <= c; j++) {
                if(map[i][j]=='c'){
                    cold(i,j,r,c,nums2);
                }
            }
        }

        for (int i = 1; i <= r; i++) {
            for (int j = 1; j <= c; j++) {
                if(map[i][j]=='m'){
                    warm(i,j,r,c,nums);
                }
            }
        }
        int findr = 0;int findc = 0;
        for (int i = 1; i <= r; i++) {
            for (int j = 1; j <= c; j++) {
                if(map[i][j]=='w'){
                    if(nums[i][j]==0 || nums[i][j]==2){
                        findr = i;
                        findc = j;
                    }
                }
            }
        }
        if(findc==0){
            System.out.println("Too cold!");
            return ;
        }
        //System.out.println(findr+" "+findc);
        for (int i = findr-1; i <= findr+1; i++) {
            for (int j = findc-1; j <= findc+1; j++) {
                if(i==findr&&j==findc) continue;
                if(map[i][j]=='.' && nums2[i][j]!=2){
                    System.out.println(i+" "+j);
                }
            }
        }
    }

    public static void cold(int r,int c,int rMax,int cMax, int[][] nums){
        for (int i = Math.max(r-1,1); i <= Math.min(r+1,rMax); i++) {
            for (int j = Math.max(c-1,1); j <= Math.min(c+1,cMax); j++) {
                nums[i][j] = 2;
            }
        }
    }

    public static void warm(int r,int c,int rMax,int cMax, int[][] nums){
        for (int i = Math.max(r-1,1); i <= Math.min(r+1,rMax); i++) {
            for (int j = Math.max(c-1,1); j <= Math.min(c+1,cMax); j++) {
                nums[i][j] = 1;
            }
        }
    }

    //谁出现了
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[21];
        nums[1] = 12; nums[2] = 9; nums[3] = 7; nums[4] = 5; nums[5] = 4; nums[6] = 3; nums[7] = 3;
        Arrays.fill(nums,8,11,2); Arrays.fill(nums,11,16,1);
        int[] scores = new int[21];
        while(n>0){
            int index = 0;
            int val = 0;
            for (int i = 1; i <= 20; i++) {
                index = scanner.nextInt();
                val = scanner.nextInt();
                scores[i] += val;
                scores[i] += nums[index];
            }
            n--;
        }
        for (int i = 1; i <= 20; i++) {
            System.out.println(i+" "+scores[i]);
        }
    }
    public static void main (String arg[]){
        System.out.println();
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[21];
        nums[1] = 12;nums[2] = 9;nums[3]  =7;nums[4] = 5;
        nums[5] = 4;nums[6] = 3;nums[7] = 3;
        Arrays.fill(nums,8,11,2);
        Arrays.fill(nums,11,16,1);
        int[] scores = new int[21];
        while(n>0){
            int index  =0;
            int val = 0;
            for(int i = 1;i<=20;i++){
                index = scanner.nextInt();
                val = scanner.nextInt();
                scores[i] += val;
                scores[i] += nums[index];
            }
            n--;
        }
        for(int i=1;i<=20;i++){
            System.out.println(i+" "+scores[i]);
        }
    }


    //热热热~
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int day = scanner.nextInt();
        int count = 0;
        int notCount = 0;
        //int[] nums = new int[n];
        int val = 0;
        for (int i = 0; i < n; i++) {
            val = scanner.nextInt();
            if(val>=35){
                if(day!=4){
                    count++;
                }else {
                    notCount++;
                }
            }
            day = day%7+1;
        }
        System.out.println(count+" "+notCount);
    }
}
